package com.ricky.mq.client.code.handler;

import cn.hutool.json.JSONUtil;
import com.ricky.mq.client.code.listener.MsgAssignment;
import com.ricky.mq.client.message.TextMsg;

import java.nio.channels.SocketChannel;

/**
 * 队列消息监听器
 *
 * @author ricky
 * @since 2020.06.18
 */
public class ListenerTopicMsgHandler implements Handler {

    private static ListenerTopicMsgHandler listenerTopicMsgHandler = new ListenerTopicMsgHandler();

    public static ListenerTopicMsgHandler getListenerTopicMsgHandler() {
        return listenerTopicMsgHandler;
    }

    @Override
    public void handler(SocketChannel socketChannel, String data) {
        TextMsg textMsg = JSONUtil.toBean(data, TextMsg.class);
        MsgAssignment.assignmentTopicMsg(textMsg.getModelMsgName(), textMsg);
    }
}
